/*
 * > /*
>  * INSANE - Interactive Structural Analysis Environment
>  *
>  * Copyright (C) 2003-2004
>  * Universidade Federal de Minas Gerais
>  * Escola de Engenharia
>  * Departamento de Engenharia de Estruturas
>  *
>  * Author's email :     insane@dees.ufmg.br
>  * Author's Website :   http://www.dees.ufmg.br/insane
>  *
>  * This program is free software; you can redistribute it and/or
>  * modify it under the terms of the GNU General Public License
>  * as published by the Free Software Foundation; either version 2
>  * of the License, or any later version.
>  *
>  * This program is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  * GNU General Public License for more details.
>  *
>  * You should have received a copy of the GNU General Public License
>  * along with this program; if not, write to the Free Software
>  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-
> 1307, USA.
 *
 */

package br.ufmg.dees.insane.ui.rich.postp.postp_view.command;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.JMenuItem;
import javax.swing.JPopupMenu;

import br.ufmg.dees.insane.commons.command.Command;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.DesktopPostp;
import br.ufmg.dees.insane.ui.rich.postp.postp_view.InterfacePostp;

public class PopUpCommand implements Command {

	private InterfacePostp parent;
	
	/** Creates new MeshStateListCommand */
	public PopUpCommand(InterfacePostp parent) {
		this.parent = (InterfacePostp)parent;
		PopupMenu demo = new PopupMenu();
		demo.createPopupMenu();
       
	}

//	************************************************************************************************************************	
	
	public void execute() {
		
		
		
	}

//************************************************************************************************************************	
	public void undo() {
	}
	
	public void redo() {
	}
//	************************************************************************************************************************		
	public class PopupMenu {
	   
	    JMenuItem menuItem1;
	    JMenuItem menuItem2;
	    
	    public void createPopupMenu() {
	        //Create the popup menu.
	        JPopupMenu popup = new JPopupMenu();
	        menuItem1 = new JMenuItem("Information");
	        menuItem1.addActionListener(
					new ActionListener(){
						public void actionPerformed(ActionEvent event){
							InformationCommand cmd = new InformationCommand(((DesktopPostp)parent.getDesktop()));
					    	cmd.execute();
						}
					});
	        
	        popup.add(menuItem1);
	        
//	        menuItem2 = new JMenuItem("Another popup menu item");
//	        menuItem2.addActionListener(
//					new ActionListener(){
//						public void actionPerformed(ActionEvent event){
//
//						
//						}
//					});
//	        popup.add(menuItem2);
	        
	        MouseListener popupListener = new PopupListener(popup);
	        parent.getView().getDrawingArea().addMouseListener(popupListener);
	    }
	   
	    class PopupListener extends MouseAdapter {
	        JPopupMenu popup;
	        
	        PopupListener(JPopupMenu popupMenu) {
	            popup = popupMenu;
	        }

	        public void mousePressed(MouseEvent e) {
	            maybeShowPopup(e);
	        }

	        public void mouseReleased(MouseEvent e) {
	            maybeShowPopup(e);
	        }

	        private void maybeShowPopup(MouseEvent e) {
	            if (e.isPopupTrigger()) {
	                popup.show(e.getComponent(),
	                           e.getX()+5, e.getY()-15);
	            }
	        }
	    }
	    
	}//end of this internal class
	
//*****************************************************************************
}//end of this command



